package net.cloudcodex.client.character.view.panel;

import java.util.Date;

import net.cloudcodex.client.campaign.view.panel.NotificationListPanel;
import net.cloudcodex.client.character.view.CharactersView.Message;
import net.cloudcodex.client.widgets.ToggleButtonGroup;

import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.ToggleButton;

public class CharacterPanel extends DockLayoutPanel {

	public static final String CHARACTER_SHEET = "characterSheet";

	public static final String ALT_SHEET = "altCharacter";

	public static final String STORYBOARD = "storyBoard";

	private ToggleButton storyBoardButton;

	private ToggleButton characterButton;

	private ToggleButton altCharacterButton;

	private Message message;

	private final SimplePanel contentPanel = new SimplePanel();

	private NotificationListPanel notificationListPanel;

	private ToggleButtonGroup toggleButtonGroup;


	public CharacterPanel(Message message) {
		super(Unit.PX);
		// FIXME: Why style "position: relative" hide child elements?
		this.getElement().addClassName("cc-ForceStatic");
		this.message = message;
		notificationListPanel = new NotificationListPanel(
				message.getNoMessages(), message.getMessagesTitle());
		initToggleButtonGroup();
		this.addNorth(notificationListPanel, 100);
		this.addNorth(toggleButtonGroup, 26);
		this.add(contentPanel);
	}

	/**
	 * @param message
	 */
	private void initToggleButtonGroup() {
		toggleButtonGroup = new ToggleButtonGroup();
		characterButton = new ToggleButton(message.getCharactersheet());
		characterButton.setTitle(CHARACTER_SHEET);
		storyBoardButton = new ToggleButton(message.getStoryBoard());
		storyBoardButton.setTitle(STORYBOARD);
		altCharacterButton = new ToggleButton(message.getAltCharacterSheet());
		altCharacterButton.setTitle(ALT_SHEET);
		toggleButtonGroup.addButton(storyBoardButton);
		toggleButtonGroup.addButton(characterButton);
		toggleButtonGroup.addButton(altCharacterButton);
	}

	public HasClickHandlers getStoryBoardButton() {
		return storyBoardButton;
	}

	public HasClickHandlers getCharacterButton() {
		return characterButton;
	}

	public HasClickHandlers getAltCharacterButton() {
		return altCharacterButton;
	}

	public void refreshContent(IsWidget view) {
		this.contentPanel.clear();
		this.contentPanel.add(view.asWidget());
	}

	public void setMessage(Message message) {
		this.message = message;
	}


	public void addNotification(String message, Date date) {
		notificationListPanel.addNotification(message, date);
	}

	public void refreshNotification() {
		notificationListPanel.refresh();
	}

	public HasClickHandlers getNotificationListBox() {
		return notificationListPanel.getNotificationListBox();
	}

	public HasClickHandlers getToggleButtonGroup() {
		return toggleButtonGroup;
	}


	public void setSelectedButton(String selectedToggleButton) {
		this.toggleButtonGroup.setSelectedButton(selectedToggleButton);

	}
}
